using CharacterCreation.Views.Contracts;
using CharacterCreation.Data.Services;
using CharacterCreation.Data.Models;
using CharacterCreation.Views.ChildWindows;

namespace CharacterCreation.Views {
    public partial class SkillHostViewModel : BaseHostViewModel {

        SkillService _skillService = SkillService.CreateInstance();

        /// <summary>
        /// Current race
        /// </summary>
        public Skill Skill {
            get {
                return _skillService.CurrentItem;
            }
        }

        /// <summary>
        /// ctor
        /// </summary>
        public SkillHostViewModel() {
            _skillService.PropertyChanged += (s, e) => {
                if (e.PropertyName == "CurrentItem")
                    RaisePropertyChanged("Skill");
            };
        }

        /// <summary>
        /// Add a new item
        /// </summary>
        public override void Add() {
            _skillService.ClearNewItem();
            PopupWindow popupWindow = new PopupWindow(
                new BaseView[] { new SkillDetailView() { IsNewItem = true } }
            );
            popupWindow.Closing += (s, e) => {
                if (popupWindow.DialogResult != null && (bool)popupWindow.DialogResult) {
                    _skillService.SaveNewItem();
                }
            };
            popupWindow.ShowDialog();
        }

        /// <summary>
        /// Delete current item
        /// </summary>
        public override void Delete() {
            _skillService.DeleteCurrentItem();
        }

        /// <summary>
        /// Saves a character
        /// </summary>
        public override void Save() {
            _skillService.SaveCurrentItem();
        }

        /// <summary>
        /// Exports the skills
        /// </summary>
        public override void Export() {
            _skillService.Export();
        }
    }
}